package com.justnow.offer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author justnow
 * Created on 2020-10-01
 * Description
 */
public class Leetcode78_Subsets {
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        List<Integer> path = new ArrayList<>();

        backTrack(nums, 0, path);
        return res;
    }

    private void backTrack(int[] nums, int start, List<Integer> path) {
        res.add(new ArrayList<>(path));
        for (int i = start ; i < nums.length; i++) {
            path.add(nums[i]);
            backTrack(nums, i + 1, path);
            path.remove(path.size() - 1);
        }
    }

    public static void main(String[] args) {
        Leetcode78_Subsets leetcode78_subsets = new Leetcode78_Subsets();
        List<List<Integer>> subsets = leetcode78_subsets.subsets(new int[]{1, 2, 3});
        System.out.println(subsets);
    }
}
